package exam12;

import java.util.Hashtable;

/**
 * @author HB
 * @version 1.0
 * @description
 * @date 2021/7/2
 */
public class ChatGroup extends AbstractChatroom{
    private Hashtable members=new Hashtable();

    @Override
    public void register(Member member){
        if(!members.contains(member)){
            members.put(member.getName(),member);
            member.setChatroom(this);
        }
    }

    @Override
    public void sendText(String from, String to, String message){
        Member member=(Member)members.get(to);
        String newMessage=message;
        newMessage=message.replaceAll("日","*");
        newMessage=message.replaceAll("操","*");
        member.receiveText(from,newMessage);
    }

    @Override
    public void sendImage(String from, String to, String image){
        Member member=(Member)members.get(to);
        if(image.length()>8){
            System.out.println("图片过大，发送失败！");
        }
        else{
            member.receiveImage(from,image);
        }
    }
}

